ULTRA-SONIC INTERFACING WITH RASPBERRY PI
In this project Raspberry Pi used to determine the distance of an object using an ultrasonic sensor that has trigger and echo pins placed on it. The distance is calculated and displayed in serial monitor.
Synopsis:

In this project Raspberry Pi used to determine the distance of an object using an ultrasonic sensor that has trigger and echo pins placed on it. The distance is calculated and displayed in serial monitor.

Description:


Ultra-Sonic Sensor:

This sensor is used to measure the distance between the object and the sensor. The ultra-sonic sensor has 4 pins, one for power and one for ground one is trigger pin and an echo pin. This sensor measures the distance by emitting ultrasonic waves from the trigger pin and then receives the emitted waves through echo pin. Thus, the waves travel to the object and reflects back to the echo pin. Hence in this process the sound waves travel twice the distance that is one from trigger pin to object and then from object to echo pin.

Distance=Speed of sound*time

Speed of sound = 340m/s. = 3.4*10^6 mm/s.

For Micro seconds, speed of sound = 0.034mm/micro Sec.

Thus, distance for ultrasonic sensor can be determined with the formula mentioned below:

Distance=(time*0.034)/2

Where, time = the duration taken by the ultrasonic wave return back to echo pin from trigger pin.

Raspberry Pi:

Raspberry Pi is a low cost, small size computer that plugs into a computer monitor, and uses a keyboard and mouse. It is capable device that enables us to explore computing and to learn how to program in languages like scratch and python. It is capable of doing what we expect a computer to do. It has many interfaces like HDMI, multiple USB, Ethernet, onboard Wi-Fi and Bluetooth, GPIOs, USB powered etc. also supports to LINUX, Python to make easy to build applications. Raspberry is available in different versions the latest version of Raspberry Pi is Pi3+ Model and the Updated version is Pi4 model. In Raspberry Pi 3B+ Model this model is having 64-bit quad core (processor) running at 1.4GHz, dual band 2.4GHz, 5GHz wireless LAN, Bluetooth 4.2/BLE, faster Ethernet, and PoE (power on Ethernet) capability with separate PoE HAT. Raspberry Pi3 Mode B+ maintains the same footprint as raspberry Pi2 and Raspberry Pi3 Model B.


Pin configuration:

1. Vin: Two 5v pins and two 3v3 pins used for providing power supply, where processor works on 3.3v.

2. Ground: Having 8 ground Pins which are un-configurable.

3. GPIO: There are 26 input-output pins which will be used as input or output based on programming.

4. PWM: In software PWM are available for all pins but in hardware PWM is available for GPIO12, GPIO13, GPIO18, and GPIO19.

5. 2 SPI bus: These pins are used for SPI communication the pins which are used for SPI is MISO, MOSI, SCLK, CE0, and CE1

6. I2C: These pins are used for I2C communication in which DATA and CLOCK pins are used for sending data to and from the SDA connection, with the speed controlled with SCL pin and ID-SE, ID-SC are reserved for ID EEPROM.

7. TX and RX: This pins are used for UART communication.

Schematic:


Code:

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BCM)

TRIG=12

ECHO=14

GPIO.setup(TRIG, GPIO.OUT)

GPIO.setup(ECHO, GPIO.IN)

GPIO.output(TRIG, False)

time.sleep(1) #Delay of 1 second

GPIO.output(TRIG,True)

time.sleep(0.00001) #Delay of 0.00001 seconds

GPIO.output(TRIG, False)

while GPIO.input(ECHO)==0:

pulse_start=time.time()

while GPIO.input(ECHO)==1:

pulse_end=time.time()

duration=pulse_end-pulse_start

distance=duration*17150 # 17150cms 170.15Meters is Half of the Sound Speed

distance=round(distance, 2)

print “distance:”, distance, “cm”

GPIO.cleanup()

Error message here!

Show Error message here!


Forgot your password?

Error message here!

Send OTP

Error message here!

Show Error message here!


Lost your password? Please enter your email address. You will receive a password you Need.

Send Error message here!


Back to log-in

Close